package hotel.modal;

import hotel.dao.CustomerDao;
import hotel.dao.CustomerTypeDao;
import javafx.beans.property.*;

public class Customer extends CustomerType{
	private SimpleIntegerProperty customerNo;	// 客户编号
	private SimpleStringProperty name;			// 客户姓名
	private SimpleStringProperty gender;		// 客户性别
	private SimpleStringProperty certId;		// 证件号码
	private SimpleStringProperty phone;			// 联系电话
	private SimpleDoubleProperty credit;		// 积分
	
	private void init(CustomerDao cd) {
		if(cd != null) {
			this.customerNo = new SimpleIntegerProperty(cd.getCustomerNo());
			this.name = new SimpleStringProperty(cd.getName());
			this.gender = new SimpleStringProperty(cd.getGender());
			this.certId = new SimpleStringProperty(cd.getCertId());
			this.phone = new SimpleStringProperty(cd.getPhone());
			this.credit = new SimpleDoubleProperty(cd.getCredit());
		}else {
			this.customerNo = new SimpleIntegerProperty(0);
			this.name = new SimpleStringProperty("");
			this.gender = new SimpleStringProperty("M");
			this.certId = new SimpleStringProperty("");
			this.phone = new SimpleStringProperty("");
			this.credit = new SimpleDoubleProperty(0.0);
		}
	}
	
	public Customer(CustomerDao cd) {
		super(cd.getCustomerType());
		init(cd);
	}
	
	public Customer() {
		super();
		init(null);
	}
	
	public Object getDao() {
		CustomerDao cd = new CustomerDao();
		cd.setCustomerNo(customerNo.get());
		cd.setName(name.get());
		cd.setGender(gender.get());
		cd.setCertId(certId.get());
		cd.setPhone(phone.get());
		cd.setCredit(credit.get());
		cd.setCustomerTypeId(getCustomerTypeId());
		cd.setCustomerType((CustomerTypeDao)super.getDao());
		return cd;
	}

	public Customer(Customer customer, int customerTypeId, String typeName, double discountRate) {
		super(customerTypeId, typeName, discountRate);
		this.customerNo = new SimpleIntegerProperty(customer.getCustomerNo());
		this.name = new SimpleStringProperty(customer.getName());
		this.gender = new SimpleStringProperty(customer.getGender());
		this.certId = new SimpleStringProperty(customer.getCertId());
		this.phone = new SimpleStringProperty(customer.getPhone());
		this.credit = new SimpleDoubleProperty(customer.getCredit());
	}
	
	public Customer(Customer customer, CustomerType customType) {
		super(customType);
		this.customerNo = new SimpleIntegerProperty(customer.getCustomerNo());
		this.name = new SimpleStringProperty(customer.getName());
		this.gender = new SimpleStringProperty(customer.getGender());
		this.certId = new SimpleStringProperty(customer.getCertId());
		this.phone = new SimpleStringProperty(customer.getPhone());
		this.credit = new SimpleDoubleProperty(customer.getCredit());
	}
	
	public Customer(int customerNo, String name, String gender, String certId, String phone, 
			double credit, int customerTypeId, String typeName, double discountRate) {
		super(customerTypeId, typeName, discountRate);
		this.customerNo = new SimpleIntegerProperty(customerNo);
		this.name = new SimpleStringProperty(name);
		this.gender = new SimpleStringProperty(gender);
		this.certId = new SimpleStringProperty(certId);
		this.phone = new SimpleStringProperty(phone);
		this.credit = new SimpleDoubleProperty(credit);
	}
	
	public Customer(int customerNo, String name, String gender, String certId, String phone, 
			 double credit, CustomerType customType) {
		super(customType);
		this.customerNo = new SimpleIntegerProperty(customerNo);
		this.name = new SimpleStringProperty(name);
		this.gender = new SimpleStringProperty(gender);
		this.certId = new SimpleStringProperty(certId);
		this.phone = new SimpleStringProperty(phone);
		this.credit = new SimpleDoubleProperty(credit);
	}
	
	public String toString() {
		String str = String.format("CustomerNo:%d Name:%s Gender:%s CertId:%s Phone:%s Credit:%.2f", 
				customerNo.get(), name.get(), gender.get(), certId.get(), phone.get(), credit.get());
		return str + " " + super.toString();
	}

	public final SimpleIntegerProperty customerNoProperty() {
		return this.customerNo;
	}
	
	public final int getCustomerNo() {
		return this.customerNoProperty().get();
	}

	public final void setCustomerNo(final int customerNo) {
		this.customerNoProperty().set(customerNo);
	}

	public final SimpleStringProperty nameProperty() {
		return this.name;
	}

	public final String getName() {
		return this.nameProperty().get();
	}
	
	public final void setName(final String name) {
		this.nameProperty().set(name);
	}

	public final SimpleStringProperty genderProperty() {
		return this.gender;
	}

	public final String getGender() {
		return this.genderProperty().get();
	}

	public final void setGender(final String gender) {
		this.genderProperty().set(gender);
	}

	public final SimpleStringProperty certIdProperty() {
		return this.certId;
	}

	public final String getCertId() {
		return this.certIdProperty().get();
	}

	public final void setCertId(final String certId) {
		this.certIdProperty().set(certId);
	}

	public final SimpleStringProperty phoneProperty() {
		return this.phone;
	}

	public final String getPhone() {
		return this.phoneProperty().get();
	}

	public final void setPhone(final String phone) {
		this.phoneProperty().set(phone);
	}

	public final SimpleDoubleProperty creditProperty() {
		return this.credit;
	}

	public final double getCredit() {
		return this.creditProperty().get();
	}

	public final void setCredit(final double credit) {
		this.creditProperty().set(credit);
	}
}
